package com.sicong.common.listener;

import com.sicong.admin.feign.RemoteLogService;
import com.sicong.common.annotation.Log;
import com.sicong.common.core.constants.SecurityConstants;
import com.sicong.common.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Resource;

public class LogListener {

    private final RemoteLogService remoteLogService;

    @Autowired
    public LogListener(RemoteLogService remoteLogService) {
        this.remoteLogService = remoteLogService;
    }

    /**
     * 保存日志
     * @param log 日志信息
     */
    @Async
    @EventListener(Log.class)
    public void saveLog(Log log) {
        // 保存请求日志
        remoteLogService.save(LogUtil.getLog().setTitle(log.value()), SecurityConstants.SECURITY_INNER);
    }

}
